﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

public partial class yzadmin_data_class : YuuzleComic.Web.UI.ManagePage
{
    protected string json = "";
    YuuzleComic.BLL.ycclass clsbll = new YuuzleComic.BLL.ycclass();
    private JObject result = new JObject();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            switch (Request["a"])
            {
                case "list":
                    this.ProcessList();
                    break;
                case "save":
                    this.ProcessSave();
                    break;
                default:
                    break;
            }
        }
    }

    private void ProcessSave()
    {
        try
        {
            YuuzleComic.Model.ycclass cls = new YuuzleComic.Model.ycclass();
            cls.classname = Request.Form["classname"].Trim();
            cls.filename = Request.Form["filename"].Trim();
            if (string.IsNullOrEmpty(Request.Form["id"]))
            {
                clsbll.Add(cls);
            }
            else
            {
                cls.id = Convert.ToInt32(Request.Form["id"]);
                clsbll.Update(cls);
            }
            result.Add("success", true);
        }
        catch (Exception e)
        {
            result.Add("success", false);
            result.Add("errorMessage", e.Message);
        }
        finally
        {
            json = result.ToString();
        }
    }

    private void ProcessList()
    {
        try
        {
            DataSet ds = clsbll.GetAllList();
            result.Add("data", JArray.FromObject(ds.Tables[0]));
            result.Add("total", ds.Tables[0].Rows.Count);
        }
        catch (Exception e)
        {
            result.Add("success", false);
            result.Add("errorMessage", e.Message);
        }
        finally
        {
            json = result.ToString();
        }
    }
}